//
//  main.m
//  OC03_homeWork
//
//  Created by Hanlingyu on 16/7/6.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Book.h"
#import "BookManager.h"
int main(int argc, const char * argv[]) {
//   1.截取字符串"20|https://www.baidu.com"中 "|" 前面和后⾯的字符串, 并输出\n
    NSString *totalString = @"20|https://www.baidu.com";
    NSArray *totalArray = [totalString componentsSeparatedByString:@"|"];
    for (int i = 0; i < totalArray.count; i++) {
        NSString *string = totalArray[i];
        NSLog(@"%@", string);
    }
    
//   2.向可变数组里存储 int、float、double、BOOL类型等数据(不能使用字面量)\n
    
    NSNumber *intNumber = [NSNumber numberWithInt:3];
    NSNumber *floatNumber = [NSNumber numberWithFloat:12.123];
    NSNumber *doubleNumber = [NSNumber numberWithDouble:123.34];
    NSNumber *boolNumber = [NSNumber numberWithBool:NO];
    NSMutableArray *array = [NSMutableArray arrayWithObjects:intNumber, floatNumber, doubleNumber, boolNumber, nil];
    NSLog(@"%@", array);
    
//   3.实现图书管理系统(BookManager类)：\n
//     1> 使用数组管理所有书籍(Book类)。
//     2> BookManager类属性数组可以添加、删除。
//     3> 可以从数组根据书名查找书籍，并修改书籍的价格。
//     4> 展示所有书籍清单（书名）

    BookManager *bookManager = [[BookManager alloc] init];
    Book *firstBook = [[Book alloc] initWithBookName:@"a hero of our time" price:123];
    Book *secondBook = [[Book alloc] initWithBookName:@"The Romance of the Three Kingdoms" price:321];
    Book *thirdBook = [[Book alloc] initWithBookName:@"A Dream in Red Mansions" price:312];
    NSMutableArray *booksArray = [NSMutableArray arrayWithObjects:firstBook, secondBook, thirdBook, nil];
    bookManager.bookArray = booksArray;
    // 添加
    Book *fourBook = [[Book alloc] initWithBookName:@"Heroes of the Marshes" price:34];
    [bookManager addBook:fourBook];
    NSLog(@"%@", bookManager.bookArray);
    // 删除
    [bookManager removeBookWithBookName:@"A Dream in Red Mansions"];
    NSLog(@"%@", bookManager.bookArray);
    // 修改
    [bookManager reviseBookWithBookName:@"a hero of our time" revisePrice:666];
    // 所有书名
    [bookManager outPutOfAllBookName];
    
    
    return 0;
}
